package com.neuedu.yyzx.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.neuedu.yyzx.common.CommonResult;
import com.neuedu.yyzx.entity.Outgoing;
import com.neuedu.yyzx.service.IOutgoingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 外出登记 前端控制器
 * </p>
 *
 * @author dya
 * @since 2021-04-27
 */
@RestController
@RequestMapping("//outgoing")
public class OutgoingController {

    @Autowired
    IOutgoingService outgoingService;

    @RequestMapping("/list")
    CommonResult list(Page page, Outgoing outgoing){
        QueryWrapper queryWrapper=new QueryWrapper();
        queryWrapper.eq("is_deleted",0);
        if (outgoing!=null && StringUtils.isNotEmpty(outgoing.getCustomerName())){
            queryWrapper.like("customer_name",outgoing.getCustomerName());
        }
        return CommonResult.success(outgoingService.page(page,queryWrapper));
    }

    @RequestMapping("/add")
    CommonResult add(Outgoing outgoing){
        return CommonResult.success(outgoingService.saveOrUpdate(outgoing));
    }

    @RequestMapping("/getById")
    CommonResult getById(Integer outgoingId){
        return CommonResult.success(outgoingService.getById(outgoingId));
    }

    @RequestMapping("/del")
    CommonResult del(Integer outgoingId){
        UpdateWrapper updateWrapper=new UpdateWrapper();
        updateWrapper.set("is_deleted",1);
        updateWrapper.eq("outgoing_id",outgoingId);
        return CommonResult.success(outgoingService.update(updateWrapper));
    }

}
